/* --------------------------Usercode Section------------------------ */


package tleng_tp;

import java_cup.runtime.*;
import java_cup.runtime.Symbol;

%%
/* -----------------Options and Declarations Section----------------- */

%class CPLexer

/* Will switch to a CUP compatibility mode to interface with a CUP */
%cup
%unicode
%state EXPONENT
/* Macro Declarations */


/* White space is a line terminator, space, tab, or line feed. */
LineTerminator = \r|\n|\r\n
WhiteSpace     = {LineTerminator} | [ \t\f]


Ent 			= -?[0-9]+
Num				= [0-9]+(\.[0-9]+)?
Alpha			= [a-z]+|[A-Z]+
AlphaNumeric 	= ([a-z]|[A-Z]|[0-9])*

%%
/* ------------------------Lexical Rules Section---------------------- */


{WhiteSpace} 			{ /* ignore white space */ }

<EXPONENT> {Ent}      	{
		yybegin(YYINITIAL);
		return new Symbol(sym.ENTERO, new Integer(yytext()) );
}

{Num} 					{ return new Symbol(sym.NUMERO, new Double(yytext()) ); }

"var"      				{return new Symbol(sym.VAR); }
"unidades"      		{return new Symbol(sym.UNI); }


{Alpha}{AlphaNumeric}	{ return new Symbol( sym.ID, yytext() ); }

"+"	      { return new Symbol( sym.MAS ); }
"-"	      { return new Symbol( sym.MENOS ); }
"*"	      { return new Symbol( sym.MULT ); }
"/"	      { return new Symbol( sym.DIV ); }
"^"	      { yybegin(EXPONENT); 
			return new Symbol( sym.POT ); }
"="	      { return new Symbol( sym.EQ ); }
"("	      { return new Symbol( sym.LPAREN ); }
")"	      { return new Symbol( sym.RPAREN ); }
","	      { return new Symbol( sym.COMA ); }
";"	      { return new Symbol( sym.PCOMA ); }

. 						{ System.err.println("ERROR: Caracter inesperado " + yytext()); }

